package alibaba.d20210910.t1;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Set;

/**
 * @author habitplus
 * @since 2021-09-10 18:57
 */
public class Main {
    private static final StreamTokenizer st = new StreamTokenizer(
            new BufferedReader(new InputStreamReader(System.in)));

    static int nextInt() {
        try {
            st.nextToken();
            return (int) st.nval;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return 0;
    }

    private static int solve(int a, int b) {
        Queue<Integer> que = new LinkedList<>();
        Set<Integer> set = new HashSet<>();
        int k = 1;
        que.offer(a);
        set.add(a);
        while (!que.isEmpty()) {
            if (set.contains(b)) {
                return k - 1;
            }

            for (int i = que.size(); i > 0; i--) {
                int cur = que.poll();
                set.add(cur + k);
                que.offer(cur + k);
                set.add(cur - k);
                que.offer(cur - k);
            }
            k++;
        }

        return -1;
    }

    public static void main(String[] args) {
        int t = nextInt();
        int a, b, ans;
        while (t-- > 0) {
            a = nextInt();
            b = nextInt();
            ans = solve(a, b);
            System.out.println(ans);
        }
    }
}
